package cn.supermarket.controller;

import cn.supermarket.mapper.RetailMapper;
import cn.supermarket.pojo.dto.RetailDetailsDTO;
import cn.supermarket.pojo.vo.RetailDetailVO;
import cn.supermarket.service.iservice.IRetailService;
import cn.supermarket.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@RequestMapping("/retails")
@RestController
@Slf4j
@Api(tags = "零售")
public class RetailController extends BaseController{
    @Autowired
    IRetailService retailService;

    //添加商品
    @PostMapping("/insert/add")
    @ApiOperation("添加零售记录")
    public JsonResult<Void> addNew(@RequestBody  RetailDetailsDTO retailDetailsDTO){

        retailService.addNew(retailDetailsDTO);
        return JsonResult.ok();
    }
    //修改备注
    @GetMapping("/update/Other")
    @ApiOperation("修改备注")
    public JsonResult<Void> updateByOther(Long id,String other){
        retailService.updateByOther(id, other);
        return JsonResult.ok();
    }

    //修改是否可见
    @GetMapping("/update/display")
    @ApiOperation("修改是否可见")
    public JsonResult<Void> updateByIsDisplay(Long id,Integer isDisplay){
        retailService.updateByIsDisplay(id,isDisplay);
        return JsonResult.ok();
    }
    //作废
    @GetMapping("/update/cancel")
    @ApiOperation("作废")
    public JsonResult<Void> updateByIsCancel(Long id){
        retailService.updateByIsCancel(id);
        return JsonResult.ok();
    }
    //锁定
    @GetMapping("/update/enable")
    @ApiOperation("修改锁定")
    public JsonResult<Void> updateByIsEnable(Long id,Integer isEnable){
        retailService.updateByIsEnable(id, isEnable);
        return JsonResult.ok();
    }
    //根据订单号查询
    @GetMapping("/select/order-number")
    @ApiOperation("订单号查询")
    public JsonResult<List<RetailDetailVO>> getByOrderNumber(String orderNumber){
        return JsonResult.ok(retailService.getByOrderNumber(orderNumber));
    }
    //根据日期查询
    @GetMapping("/select/data")
    @ApiOperation("日期查询")
    public JsonResult<List<RetailDetailVO>> getByData(Date dateStart,Date dateEnd){
        return JsonResult.ok(retailService.getByData(dateStart,dateEnd));
    }
    //金钱
    @GetMapping("/select/payment")
    @ApiOperation("金钱范围")
    public JsonResult<List<RetailDetailVO>> getByPaymentAmount(BigDecimal initialAmount, BigDecimal finish){
        return JsonResult.ok(retailService.getByPaymentAmount(initialAmount,finish));
    }

}
